﻿function STaffTimeEditController($scope, service, $routeParams, $location, $http, $filter) {
    
    $scope.dataSelect = [
        {CheckId: '1',
            CheckType:'Check In'},
        {CheckId: '2',
            CheckType: 'Check Out'},
        {CheckId: '3',
            CheckType: 'Start Break'},
        {CheckId: '4',
        CheckType: 'End Break'},
        {CheckId: '5', 
            CheckType: 'Go Out'},
        {CheckId: '6',
            CheckType: 'Turn Back'}
        ];
    $scope.checkType = 'Normal';
    $scope.checkTypeEdit = 'Normal';
    //Time
    var s = "2012-10-16T17:57:28.556094Z";
    $scope.v = {
        Dt: Date.now(),
        sDt: s,
        DDt: Date.parse(s)
    }
    $scope.showTest = true;
    var dateForgot = Date.parse($routeParams.date);
    //AAbc
    $scope.mytime = new Date();

    $scope.hstep = 1;
    $scope.mstep = 15;

    $scope.options = {
        hstep: [1, 2, 3],
        mstep: [1, 5, 10, 15, 25, 30]
    };

    $scope.ismeridian = true;
    $scope.toggleMode = function () {
        $scope.ismeridian = !$scope.ismeridian;
    };

    $scope.update = function () {
        var d = new Date();
        d.setHours(14);
        d.setMinutes(0);
        $scope.mytime = d;
    };

    $scope.changed = function () {
        console.log('Time changed to: ' + $scope.mytime.toString('HH:mm'));
    };
    //End
    //get id
    $http.get(service.locationUrl + "/stafftimeedit/" + $routeParams.Id + "/date/" + dateForgot.toString('yyyy-MMM-dd'), {})
        .success(function (data) {
            data.StampDate = $filter('date')(data.StampDate, 'yyyy-MM-dd');
            $scope.Staff = data;
            $scope.myStore = data.StoreId;
            console.log($scope.myStore);

            if ($scope.Staff.CheckIn == 0) {
                $scope.checkType = 'Check In';
                $scope.checkTypeEdit = 'Check Out';

            }
            if ($scope.Staff.CheckOut == 0) {
                $scope.checkType = 'Check Out';
                $scope.checkTypeEdit = 'Check In';
            }

        })
        .error(function (err) {

            console.log("error", err);
        });

    //get data of Store list
    $http.get(service.locationUrl + "/storelist/" + service.infoUser.Id, {})
        .success(function (data) {
            $scope.rowsStoreList = data;

        })
        .error(function (err) {

            console.log("error", err);
        });

    //btn back
    $scope.back = function ()
    {
        $location.path("/StaffTime");
    }

    //go to next page send param 
    $scope.verifyInput = function ()
    {
        $location.path("/StaffTimeEditConfirm/" + $routeParams.Id).search({
            remark: $scope.remark,
            editTime: $scope.editDate,
            recordDate: $scope.mytime.toString('HH:mm'),
            checkType: $scope.checkType,
            storeIdOld: $scope.Staff.StoreId,
            storeID: $scope.myStore,
            StaffTimeTableId : $scope.Staff.StaffTimeTableId,
            dateForgot: dateForgot
        });
    }

    //// delete input in test
    $scope.redo = function ()
    {
        $scope.recordDate = '';
        $scope.editDate = '';
        $scope.remark = '';
    }
    /// Edit type forgot
    $scope.editType = function ()
    {
        $scope.checkType = $scope.checkTypeEdit;
    }
    $scope.createNew = function () {
        //$scope.showTest = false;
        //console.log("check Type" + $scope.typeSelect);
    }
    if ($routeParams.type == 'edit') {
        $scope.showTest = false;
    }
    $scope.updateType = function () {
        $scope.checkType = $scope.typeSelect;
        console.log("check Type" + $scope.checkType);
    }
}

